package com.easywan.service.impl;

import java.util.List;

import com.easywan.dao.IBaseDao;
import com.easywan.service.BaseService;
import com.easywan.util.Utils;
import com.easywan.vo.AdminMenue;
import com.easywan.vo.base.BaseModel;

public abstract class BaseServiceImpl implements BaseService{
	public BaseServiceImpl(){
		
	}
	public List<BaseModel> selectAll(){
		return getMapper().select();
	}
	public abstract IBaseDao getMapper();
	@Override
	public <T extends BaseModel> List<T> list(T model) {
		//if(mapper == null) throw new Exception("mapper没有被初始化");
		List<T> list = getMapper().selectByPage(model);
		if(model.getPage() != null)
		model.getPage().setPageCount(getMapper().countTotal(model).intValue());
		return list;
	}
	@Override
	public <T extends BaseModel> int add(T model) {
		model.setCreatetime(Utils.getNowDate());
		this.getMapper().insertSelective(model);
		return 0;
	}

	@Override
	public int deleteById(Integer id) {
		return getMapper().deleteByPrimaryColumn(id);
	}
	@Override
	public <T extends BaseModel> T findById(Integer id) {
		return getMapper().selectByPrimaryColumn(id);
	}
	@Override
	public <T extends BaseModel>  void modify(T loadFiled) {
		loadFiled.setModifytime(Utils.getNowDate());
		getMapper().updateByPrimaryColumn(loadFiled);
	}
	@Override
	public <T extends BaseModel> List<T> listBySelectTive(T tempAdminMenue) {
		
		return getMapper().select(tempAdminMenue);
	}
	
	
}
